﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pavilion.Communications;

namespace Pavilion.DesignerTool
{
    class NodeScriptTransfer
    {
        static public void Add(string resourceName, NodeScript nodeScript)
        {
            DataTransferClient.Instance.TransferData((proxy) => proxy.AddNodeScript(resourceName, nodeScript.Name));

            NodeTransfer.AddInternalNodeContent(resourceName, nodeScript.Name, nodeScript.RootContainer.EntryNode);

            foreach (NodeBase node in nodeScript.RootContainer.NodeCollection.Where(x => !(x is EntryNode)))
                NodeTransfer.Add(resourceName, nodeScript.Name, node);

            foreach (Link newLink in nodeScript.RootContainer.LinkCollection)
                LinkTransfer.Add(resourceName, nodeScript.Name, nodeScript.RootContainer, newLink);
        }

        static public void Remove(string resourceName, NodeScript nodeScript)
        {
            DataTransferClient.Instance.TransferData((proxy) => proxy.RemoveNodeScript(resourceName, nodeScript.Name));
        }

        static public void Rename(string resourceName, string oldName, string newName)
        {
            DataTransferClient.Instance.TransferData((proxy) => proxy.RenameNodeScript(resourceName, oldName, newName));
        }
    }
}
